package com.nd.qa.shareplate.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nd.qa.shareplate.model.TestStep;
import com.nd.qa.shareplate.service.TestClassService;
import com.nd.qa.shareplate.service.TestStepService;
import com.nd.qa.shareplate.util.JsonUtil;

@Controller
@RequestMapping("/case/*")
public class CaseController {

	private static Logger log = LoggerFactory.getLogger(CaseController.class);
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.TestClassService")
	private TestClassService testClassService;
	
	@Autowired
	@Qualifier("com.nd.qa.shareplate.service.TestStepService")
	private TestStepService testStepService;
	
	/**
	 * 
	 * @param request
	 * @param response
	 * @param session
	 * @param params
	 */
	@RequestMapping("/getStepInfo")
	public String getStepInfo(HttpServletRequest request,HttpServletResponse response,HttpSession session,@RequestBody String params,Model model ){
		
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		try {
			HashMap<String, Object> inParam = JsonUtil.toObject(params, HashMap.class);
			Integer caseId = Integer.valueOf(String.valueOf(inParam.get("caseId")));
			Integer projectId = Integer.valueOf(String.valueOf(inParam.get("projectId")));
			Integer classId = Integer.valueOf(String.valueOf(inParam.get("classId")));
			Integer totalCase = Integer.valueOf(String.valueOf(inParam.get("totalCase")));
			String projectName = String.valueOf(inParam.get("projectName"));
			TestStep testStep = new TestStep();
			testStep.setCaseId(caseId);
			List<TestStep> stepList = testStepService.queryTestStepById(testStep);
			model.addAttribute("stepList", stepList);	
			model.addAttribute("projectId", projectId);	
			model.addAttribute("classId", classId);	
			model.addAttribute("totalCase", totalCase);	
			model.addAttribute("projectName", projectName);	
		}catch (Exception e) {
			log.error(e.toString());
			e.printStackTrace();
		}
		return "/main/stepIndex";
	}
	
}
